package com.masterclient.app.businessmodule.homemodule.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.utils.GlideUtil;
import com.masterclient.app.R;
import com.masterclient.app.businessmodule.homemodule.view.adapter.saletab.TimeLimitedProductAdapter;
import com.masterclient.app.modules.income.model.HomeDataBean;
import java.util.List;

public class HotMeetItemAdapter extends BaseQuickAdapter<HomeDataBean.HotEventItem, BaseViewHolder> {

    private OnClickStatusListener clickStatusListener;

    public HotMeetItemAdapter(@Nullable List<HomeDataBean.HotEventItem>  data) {
        super(R.layout.hot_meet_item, data);
    }

    public interface OnClickStatusListener{
        void clickStatusBtn(String eventId,int position);
    }

    public void setOnClickStatusListener(OnClickStatusListener clickStatusListener){
        this.clickStatusListener = clickStatusListener;
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeDataBean.HotEventItem item) {
        ImageView iv = helper.getView(R.id.iv_img);
        TextView tvName = helper.getView(R.id.tv_name);
        TextView tvCity = helper.getView(R.id.tv_city);
        TextView tvStatus = helper.getView(R.id.tv_status);
        View viewStatus = helper.getView(R.id.view_status);
        ImageView ivStatus = helper.getView(R.id.iv_status);
        TextView tvStatusTxt = helper.getView(R.id.tv_status_txt);
        tvName.setText(item.name);
        tvCity.setText(item.city+" "+item.eventTime);
        tvStatus.setText(item.statusText);

        if ("2".equals(item.status)){
            //进行中
            tvStatus.setBackgroundResource(R.mipmap.icon_meeting_hot_tag);
            viewStatus.setVisibility(View.GONE);
        }else if("1".equals(item.status)){
            //进行中
            tvStatus.setBackgroundResource(R.mipmap.icon_meet_pre_tag);
            viewStatus.setVisibility(View.VISIBLE);
        }else{
            //已结束
            tvStatus.setBackgroundResource(R.mipmap.icon_meet_end_hot_tag);
            viewStatus.setVisibility(View.GONE);
        }

        if ("0".equals(item.hasSubscribe)){
            viewStatus.setBackgroundResource(R.drawable.bg_meet_subscribe);
            ivStatus.setImageResource(R.mipmap.icon_alarm);
            tvStatusTxt.setText("预约提醒");
            viewStatus.setOnClickListener(view -> {
                clickStatusListener.clickStatusBtn(item.event_id,helper.getAdapterPosition());
            });
        }else {
            viewStatus.setBackgroundResource(R.drawable.bg_meet_has_subscribe);
            ivStatus.setImageResource(R.mipmap.icon_alarmed);
            tvStatusTxt.setText("已预约");
        }
        GlideUtil.displayImage(mContext,item.image,iv,R.mipmap.defaults);
    }
}
